package com.qiujie.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.poi.ss.formula.functions.T;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 休假枚举类
 */

@Getter
public enum LeaveEnum implements BaseEnum<T> {

    PERSONAL_LEAVE(0, "事假"),
    MATERNITY_LEAVE(1, "生育假"),
    SICK_LEAVE(2, "病假"),
    MARRIAGE_LEAVE(3, "婚假"),
    HOME_LEAVE(4, "探亲假"),
    PATERNITY_LEAVE(5, "陪待假"),
    TIME_OFF(6, "调休"),
    ANNUAL_LEAVE(7,"年休假"),
    WORKIN_JURY_LEAVE(8,"工伤"),
    BEREAVEMENT_LEAVE(9,"丧假"),
    ABORTION_LEAVE(10,"流产假"),
    PREGNANCY_CHECK_UP_LEAVE(11,"孕期检查假"),
    NURSING_LEAVE(12,"护理育儿假"),
    BIRTH_CONTROL(13,"节育绝育假"),
    BREASTFEEDING(14,"哺乳假");


    @EnumValue
    private final Integer code;
    @JsonValue
    private final String message;

    // 必须显式声明构造方法
    LeaveEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    // 新增方法：通过code获取枚举实例
    public static LeaveEnum fromCode(Integer code) {
        return Arrays.stream(values())
                .filter(e -> e.code.equals(code))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效类型码：" + code));
    }

    // 新增方法：获取所有有效code值
    public static List<Integer> validCodes() {
        return Arrays.stream(values())
                .map(LeaveEnum::getCode)
                .collect(Collectors.toList());
    }

    public static boolean isValidCode(Integer code) {
        return Arrays.stream(values())
                .anyMatch(e -> e.code.equals(code));
    }

    public static void validateCode(Integer code) {
        if (!isValidCode(code)) {
            throw new IllegalArgumentException("无效请假类型编码: " + code);
        }
    }


}



